package com.niuxiaofa.newlaw.Fragment;

import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.niuxiaofa.newlaw.Activity.AnswerQuestionsSignActivity;
import com.niuxiaofa.newlaw.Activity.AwardRankingActivity;
import com.niuxiaofa.newlaw.Activity.CourseActivity;
import com.niuxiaofa.newlaw.Activity.HarvestRankingActivity;
import com.niuxiaofa.newlaw.Activity.LawUniversalRankingActivity;
import com.niuxiaofa.newlaw.Activity.MyClassActivity;
import com.niuxiaofa.newlaw.Activity.MyCreditsActivity;
import com.niuxiaofa.newlaw.Activity.RoadGrowthActivity;
import com.niuxiaofa.newlaw.Base.BaseFragment;
import com.niuxiaofa.newlaw.Bean.BannerBean;
import com.niuxiaofa.newlaw.Bean.UserInfoBean;
import com.niuxiaofa.newlaw.Network.NewsPresenter;
import com.niuxiaofa.newlaw.Network.UserPresenter;
import com.niuxiaofa.newlaw.R;
import com.niuxiaofa.newlaw.Tools.ToActivityUtil;
import com.niuxiaofa.newlaw.adapter.BannerCreator;
import com.to.aboomy.banner.Banner;
import com.to.aboomy.banner.IndicatorView;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import www.linwg.org.lib.LCardView;


/**
 * 普法
 */
public class LawUniversalFragment extends BaseFragment implements NewsPresenter.interface_getStartBannerByType, UserPresenter.interface_userInfo {


    @BindView(R.id.energy_ranking)
    LinearLayout energy_ranking;

    @BindView(R.id.is_login)
    LinearLayout is_login;

    @BindView(R.id.coin_raking)
    LinearLayout coin_raking;

    @BindView(R.id.law_ranking)
    LinearLayout law_ranking;

    @BindView(R.id.kecheng)
    RelativeLayout kecheng;

    @BindView(R.id.roadgrowth)
    RelativeLayout roadgrowth;


    @BindView(R.id.banner)
    Banner banner;

    @BindView(R.id.dtqd)
    LinearLayout dtqd;


    @BindView(R.id.my_class)
    RelativeLayout my_class;

    @BindView(R.id.lcard)
    LCardView lcard;

    @BindView(R.id.balance)
    TextView balance;

    @BindView(R.id.xf)
    TextView xf;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_law_universal;
    }


    @Override
    public void onStart() {
        super.onStart();
        UserPresenter.userInfo(this);
    }

    public void setIs_login(boolean ISLOGIN) {
        if (ISLOGIN) {
            is_login.setVisibility(View.GONE);
        } else {
            is_login.setVisibility(View.VISIBLE);
        }

    }


    @Override
    public void initData() {
        UserPresenter.userInfo(this);
        Map map = new HashMap();
        map.put("bannerType", "2");
        NewsPresenter.bannerListByType(map, this);

        energy_ranking.setOnClickListener(e -> {
            ToActivityUtil.toNextActivity(AwardRankingActivity.class);
        });

        coin_raking.setOnClickListener(e -> {
            ToActivityUtil.toNextActivity(HarvestRankingActivity.class);
        });


        law_ranking.setOnClickListener(e -> {
            ToActivityUtil.toNextActivity(LawUniversalRankingActivity.class);
        });
        kecheng.setOnClickListener(e -> {
            ToActivityUtil.toNextActivity(CourseActivity.class);
        });

        roadgrowth.setOnClickListener(e -> {
            ToActivityUtil.toNextActivity(RoadGrowthActivity.class);
        });

        dtqd.setOnClickListener(e -> {
            ToActivityUtil.toNextActivity(AnswerQuestionsSignActivity.class);
        });
        my_class.setOnClickListener(e -> {
            ToActivityUtil.toNextActivity(MyClassActivity.class);
        });
        lcard.setOnClickListener(e -> {

            ToActivityUtil.toNextActivity(MyCreditsActivity.class);
        });

    }

    @Override
    public void addData(BannerBean u) {
        if (u.getCode() == 1) {
            //使用内置Indicator
            IndicatorView indicator = new IndicatorView(getContext())
                    .setIndicatorColor(Color.DKGRAY)
                    .setIndicatorSelectorColor(Color.WHITE);

            banner.setIndicator(indicator).setHolderCreator(new BannerCreator(new BannerCreator.Onclick() {
                @Override
                public void click(int id) {
//                    String[][] a = new String[][]{{"url", u.getData().get(id).getTargetUrl()}, {"title", u.getData().get(id).getSTitle()}};
//                    ToActivityUtil.toNextActivity(WebViewActivity.class, a);
                }
            })).setPages(u.getData());

        }
    }

    @Override
    public void getResponse(UserInfoBean u) {
        if (u.getCode() == 1) {

            setIs_login(true);
            balance.setText("￥" + u.getData().getBalance());
            xf.setText("累积学分：" + u.getData().getCredit());
        } else {
            setIs_login(false);
        }
    }
}
